import java.util.Scanner;
import java.util.LinkedList;

//核心思想：i = (i+2)%list.size();
public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            int n = sc.nextInt();
            if(n > 1000){
               n = 999;
            }
            LinkedList<Integer> list = new LinkedList<>();
            for(int i = 0; i < n; i++){
               list.add(i);
            }
            int i = 0;
            while(list.size() > 1){
               i = (i+2)%list.size();
               list.remove(i);
            }
            System.out.println(list.get(0));
        }
    }
}